﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PostSharp.Laos;
using System.Reflection;

namespace PostSharpAssembly
{
    [Serializable]
    public class OnMyExceptionAspect : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            base.OnEntry(eventArgs);
            Console.WriteLine("OnEntry Method：{0}", eventArgs.Method.Name);
            object[] arguments = eventArgs.GetReadOnlyArgumentArray();
            ParameterInfo[] parameters = eventArgs.Method.GetParameters();
            for (int i = 0; arguments != null && i < arguments.Length; i++)
            {
                Console.WriteLine("参数{0} {1}：{2}", i + 1, parameters[i].Name, arguments[i]);
            }
        }

        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            base.OnExit(eventArgs);
            Console.WriteLine("OnExit Method：{0}", eventArgs.Method.Name);
        }

        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("发生异常：{0}", eventArgs.Exception.Message);
            base.OnException(eventArgs);
        }
    }
}
